package com.chookss.video

import android.view.View
import com.chookss.tools.MyEvent
import com.chookss.tools.NavigationTools
import com.chookss.video.entity.VideoEntity
import com.chookss.video.model.VideoSourceModel
import kotlinx.android.synthetic.main.activity_base_video_play.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 * Company:
 * Project:
 * Author: liuhaoge
 * Date: 2021/1/20 16:17
 * Note:
 */
class VideoOnePlayActivity : BaseVideoPlayActivity() {
    private lateinit var videoEntity: VideoEntity

    //    private var type: Int = 0 // 1学习任务过来直接播放0默认
    private var isTaskComplete = false //播放时间可以达到完成任务了

    override fun initOnCreate(): Boolean {
        var tmp = intent?.getSerializableExtra("video")
        if (tmp == null) {
            return false
        }
//        type = intent.getIntExtra("type", 0)
        videoEntity = tmp!! as VideoEntity
        videoEntity.isTask = "1"
        return true
    }

    override fun initVideoPlayView() {
        super.initVideoPlayView()
        videoPlayView.videoAdapter.setOnUpdateHolder { holder, position, entity ->
            holder.tvSetsInfo.visibility = View.GONE
            holder.tvMmarquee.visibility = View.GONE
            holder.tvOnePlay.visibility = View.VISIBLE
        }

    }

    var hasInitedPlayerData = false
    override fun loadPlayList(isLoadMoreData: Boolean) {
        handler.postDelayed({
            if (hasInitedPlayerData) {
                videoPlayView.completeLoadState(true)
            } else {
                hasInitedPlayerData = true
                videoPlayView.refreshVideoList(arrayListOf(VideoSourceModel(videoEntity)), true)
            }
        }, 1)
    }

    override fun initData() {
        ivLeft.setOnClickListener {
            videoPlayView.videoListView.addPlayCount()
            finish()
        }

    }

    override fun onBackPressed() {
        videoPlayView.videoListView.addPlayCount()
        super.onBackPressed()
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    override fun onMoonEvent(messageEvent: MyEvent) {
        //事件订阅者处理事件
        if (messageEvent.hashMap != null) {
            val map: Map<String, String?> = messageEvent.hashMap
        } else {
            val msg = messageEvent.message
            if (msg?.equals("DeleteVideo")!!) {
                finish()
            }
        }
    }
}